Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when shifting int by non-const #4653

Merged
merged 4 commits into from
May 7, 2024

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented May 6, 2024

Fixes #4652. Note that besides changing the error I've also allowed the case when the right operand is bit<N>/int<N> but it is also constant. This case should be allowed and it does actually work in most cases in practice, it is just covered by constant folding.


BTW: I did not realize until now that the type checker actually does constant folding too! This will make any "small frontend" quite hard to do if it was to not do constant folding.

@vlstill vlstill added enhancement This topic discusses an improvement to existing compiler code. core Topics concerning the core segments of the compiler (frontend, midend, parser) labels May 6, 2024
@vlstill vlstill self-assigned this May 6, 2024
@fruffy
Copy link
Collaborator

fruffy commented May 6, 2024

BTW: I did not realize until now that the type checker actually does constant folding too! This will make any "small frontend" quite hard to do if it was to not do constant folding.

Yes, I believe this is necessary to fold compile-time arithmetic in bit<> types. At least the constantFolding pass is relatively self-contained and can be applied without a type or ref-map. We could fork out a smaller version that only works on compile-time constants and is used for the purpose of type inference.

It could then be extended by the full ConstantFolding pass.

@vlstill vlstill added this pull request to the merge queue May 7, 2024
Merged via the queue into main with commit 7c3a9d2 May 7, 2024
16 of 17 checks passed
@vlstill vlstill deleted the vstill/int-shift-error branch May 7, 2024 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser) enhancement This topic discusses an improvement to existing compiler code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong error message when arbitrary-precision int is shifted by runtime value
3 participants